import { NextRequest } from "next/server";
import { withMiddleware } from "@/lib/middleware/entry";
import { prisma } from "@/lib/prisma";

async function handler(req: NextRequest) {
  const { contentId } = await req.json();

  if (!contentId) {
    throw new Error("内容ID不能为空");
  }

  await prisma.content.update({
    where: { id: contentId },
    data: {
      viewCount: {
        increment: 1,
      },
    },
  });

  return { message: "操作成功" };
}

export const POST = withMiddleware(handler);